<template>
  <div >
        <el-form :model="queryParams" ref="queryForm" :inline="true"  label-width="68px" @submit.native.prevent>
          <el-form-item label="评教批次" prop="status">
            <el-select
              v-model="queryParams.semCode"
              placeholder="评教批次"
              clearable
              size="small"
              style="width: 240px"
              @change="selectEvaluation"
            >
            <el-option
                v-for="dict in sems"
                :key="dict.id"
                :label="dict.format"
                :value="dict.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="教师名称" prop="teachName">
            <el-input
              v-model="queryParams.teachName"
              placeholder="模糊查询"
              clearable
              size="small"
              style="width: 240px"
              @keyup.enter.native="selectEvaluation"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="selectEvaluation">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
        <el-table v-loading="loading" :data="evaluationList">
          <el-table-column label="教师姓名" align="center" key="teachName" prop="teachName" v-if="columns[1].visible" :show-overflow-tooltip="true" />
          <el-table-column label="课程" v-if="meRole.role == '3'" align="center" key="courseName" prop="courseName"  />
          <el-table-column label="批次名称" align="center" key="semName" prop="semName" v-if="columns[1].visible" :show-overflow-tooltip="true" />
          <el-table-column label="开始时间" align="center" key="startDate" prop="startDate" v-if="columns[2].visible" :show-overflow-tooltip="true" />
          <el-table-column label="结束时间" align="center" key="endDate" prop="endDate" v-if="columns[4].visible" :show-overflow-tooltip="true" />
          <el-table-column label="状态" :formatter="Status"  align="center" key="status" prop="status" v-if="columns[5].visible" width="120" />
          <el-table-column
            label="操作"
            align="center"
            width="160"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope"> 
              <div>
                <div v-if="scope.row.status == '1' && scope.row.isEnd!=1">
                  <el-button  v-if="meRole.role == '2'&&scope.row.teachCode == meRole.id"
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleMeEvaluation(scope.row)"
                >自评</el-button>
                <el-button v-else
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleEvaluation(scope.row)"
                >评教</el-button>
                </div>
                <div v-else-if="scope.row.isEnd==1">
                  已评教
                </div>
              </div>
            </template>
          </el-table-column>
        </el-table>


        <pagination
          v-show="this.sum>0"
          :total="this.sum"
          :page.sync='queryParams.page'
          :limit.sync='queryParams.number'
          @pagination="selectEvaluation(false)"
        />
     
 <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="titleQuestionnaire" :visible.sync="open" width="1000px" append-to-body>
      <template v-for='questionnaire in questionnaireList' >
        <div :key="questionnaire.id">
          <div class="mainTitle">
            <span  class="title">{{ questionnaire.name }}</span>
         </div>
         <questionnaire :radio="radio" :hierarchy="hierarchy" :questionnaireList = "questionnaire.children" v-if="questionnaire.children!=null && questionnaire.children.length>0"></questionnaire>
        </div>
      </template>
      <div slot="footer" class="dialog-footer btton">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {getMeStuentOrTeacherApi,getSemsApi} from "@/api/system/common"
import {selectEvaluationApi,teachaerEvaluationApi} from "@/api/system/evaluation"
import {selectQuestionnaireIndicatorOptionsApi} from "@/api/system/indicator/info"
import questionnaire from '@/components/questionnaire'
export default {
  name: "user",
  components: {
    questionnaire
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      //自己的角色
      meRole:{},
      // 用户表格数据
      evaluationList: [],
      //问卷属性
      questionnaireList:[],
      sems:[],
      //当前层
      hierarchy:0,
      //选项
      radio:[],
      submitDate:{},
      titleQuestionnaire:"",
      sum: 0,
      //评教页
      open: false,
      // 查询参数
      queryParams: {
        page: 1,
        number: 10,
        teachName: undefined
      },
      // 列信息
      columns: [
        { key: 0, label: `用户编号`, visible: true },
        { key: 1, label: `用户名称`, visible: true },
        { key: 2, label: `登录账号`, visible: true },
        { key: 3, label: `部门名称`, visible: true },
        { key: 4, label: `性别`, visible: true },
        { key: 5, label: `手机号码`, visible: true },
        { key: 6, label: `邮箱`, visible: true },
        { key: 7, label: `状态`, visible: true },
        { key: 8, label: `创建时间`, visible: true }
      ],
      // 表单校验
      rules: {
        
      }
    };
  },
  watch: {

  },
  created() {
    getSemsApi().then(data=>{
      this.sems = data.data;
      if(this.sems!=null && this.sems!=[]){
        this.queryParams.semCode = this.sems[0].id;
          getMeStuentOrTeacherApi().then(data=>{
          this.meRole = data.data;
          this.selectEvaluation();
        })
      }
    })
  },
  methods: {
    //查询
    selectEvaluation(){
     selectEvaluationApi(this.queryParams).then(data=>{
        this.evaluationList = data.data.returnDate;
        this.sum = data.data.paginationData.sum;
        this.loading = false;
      }).catch(()=>{
        this.evaluationList = null;
        this.sum = 0;
        this.loading = false;
      })
    },
    Status(row, column) {
      if (row.status =='0') {
        return '未开始'
      } else if(row.status =='1') {
        return '进行中'
      }else if(row.status =='2') {
        return '暂停中'
      }else if(row.status =='3') {
        return '已结束'
      }
    },
    /** 问卷按钮操作 */
    handleEvaluation(row) {
      this.reset();
      selectQuestionnaireIndicatorOptionsApi({
        "id": this.meRole.iid,
        "isQuestionnaire":true,  
        "page":1,
        "number":1 
      }).then(data=>{
       this.questionnaireList = data.data;
       if(this.questionnaireList.length>0){
         this.titleQuestionnaire = this.questionnaireList[0].name;
         this.submitDate.teachCode  = row.teachCode;
         this.submitDate.semCode  = row.semCode;
         this.submitDate.courseId  = row.courseId;
       }
       this.open = true;
      }).catch(()=>{
         this.questionnaireList = [];
         this.open = true;
      }) 
    },
    /** 重置按钮操作 */
    resetQuery() {
      if (this.$refs["queryForm"]) {
		    this.$refs["queryForm"].resetFields();
	    }
      this.selectEvaluation();
    },
     /** 提交按钮 */
    submitForm: function() {
      this.submitDate.iid = this.meRole.iid;
      this.submitDate.radio = this.radio;
      teachaerEvaluationApi(this.submitDate).then(data=>{
        this.open = false;
        this.selectEvaluation();
        this.$message({
               type: 'success',
              message: '评教成功'
        });
      })
    }, // 取消按钮
    cancel() {
      this.open = false;
    },
    reset(){
      this.submitDate={
        teachCode:undefined,
        semCode:undefined,
        courseId:undefined,
        radio:undefined,
        iid:undefined
      }
      if (this.$refs["submitDate"]) {
		    this.$refs["submitDate"].resetFields();
	    }
    }
  }
};
</script>

<style scoped>
  .mainTitle{
    display:flex;
  }
  .title{
    margin:10px auto;

    font-size: 40px;
  }
  .btton{
   text-align:center;
  }
</style>
